/*
 * Copyright (C) 2024-2025 Deepin Technology Co., Ltd.
 *
 * Author:      zhangbingyi <zhangbingyia@uniontech.com>
 *
 * Maintainer:  zhangbingyi <zhangbingyia@uniontech.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#pragma once

#include "widgets/hframe1.h"

#include <QFrame>
#include <QCheckBox>

class DLabel;
class QLabel;
class DSpinner;

/**
 * @brief The CleanerResultItemWidget class
 * 为检查项模型提供界面
 * 展示被扫描项的状态
 */
class DEVCOMMONSHARED_EXPORT CleanerResultItemWidget : public QFrame
{
    Q_OBJECT
public:
    CleanerResultItemWidget(QWidget *parent = nullptr);
    ~CleanerResultItemWidget();

    // 设置标题和提示
    void setHeadText(const QString &text);
    void setHeadTipText(const QString &text);

    // 设置右侧提示信息与使用空间大小
    void setTailText(const QString &text);
    void setUsedSpace(const QString &text);

    // 设置/获取 勾选框状态
    Q_SLOT void setCheckBoxStatus(bool isChecked);
    bool getCheckBoxStatus() const;
    void setCheckBoxVisable(bool isVisable);

    // 子项目扫描完成时显示小图标
    void setIconVisable(bool isVisable);

    void setScanning();
    Q_SLOT void setCleanDone();

    void setAsRoot();
    void setAsChild();
    void setRoot(CleanerResultItemWidget *rootItem);

    Q_SLOT void childSelected();
    void rootSelected();
    void resetElidedTextByFontChange();

public Q_SLOTS:
    // 作为根结点的工作状态启动
    void setWorkStarted(bool);
    // 对于父项或根项,增加一个不可勾选的状态,以应对"未扫描完" 和 "所有项均被清理"
    void setUncheckable();
    void setScanResult(uint, const QString &);
    void prepare();

Q_SIGNALS:
    void childClicked(bool);
    void rootClicked(bool);

protected:
    void paintEvent(QPaintEvent *event);

private:
    bool m_isRootItem; // 作为根结点展示
    QCheckBox *m_checkBox; // 作为子项是否选中
    QLabel *m_iconLable; // 扫描结束使用小图标
    QLabel *m_headLabel; // 扫描项目名称
    QLabel *m_headTipLabel; // 项目说明
    QLabel *m_tailLabel; // 状态标签
    QLabel *m_usageLabel; // 大小标签
    DSpinner *m_spinner; // 树首结点spinner
    HFrame1 *m_contentFrame;
    CleanerResultItemWidget *m_root; // 根检查项的页面
    bool m_isWorking;

    // 由于需要对界面文字遮挡问题做出处理
    // 现在需要保存被设置文字的原始值
    QString m_headStr;
    QString m_headTipStr;
    QString m_tailStr;
    QString m_usageStr;
};
